package com.ruoyi.biz.card.controller;

import com.ruoyi.biz.card.domain.CardInfo;
import com.ruoyi.biz.card.service.ICardInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/system/info")
public class CardInfoController extends BaseController
{
    @Autowired
    private ICardInfoService cardInfoService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardInfo cardInfo)
    {
        startPage();
        List<CardInfo> list = cardInfoService.selectCardInfoList(cardInfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CardInfo cardInfo)
    {
        List<CardInfo> list = cardInfoService.selectCardInfoList(cardInfo);
        ExcelUtil<CardInfo> util = new ExcelUtil<CardInfo>(CardInfo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cardInfoService.selectCardInfoById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CardInfo cardInfo)
    {
        return toAjax(cardInfoService.insertCardInfo(cardInfo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CardInfo cardInfo) {
        return toAjax(cardInfoService.updateCardInfo(cardInfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cardInfoService.deleteCardInfoByIds(ids));
    }

    /**
     * 根据id获取详情, 并且生成用户信息二维码
     *  @param id
     *  @return AjaxResult
     *  @date 2023/5/30
     */
    @GetMapping("/getInfoCard/{id}")
     public AjaxResult getCardInfo(@PathVariable Long id) {
         return cardInfoService.getCardInfo(id);
    }

    /**
     * h5新增
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/h5add")
    public AjaxResult h5add(@RequestBody CardInfo cardInfo) {
        return toAjax(cardInfoService.insertCardInfo(cardInfo));
    }
}
